package com.dongbo.recorder.screenrecord.prefrences;


import android.content.Context;
import android.content.SharedPreferences;

import com.dongbo.recorder.screenrecord.AppLpds;


public class PreferencesLocalDataSource implements PreferencesDataSource {
    private SharedPreferences mSharedPreferences;

    private static PreferencesLocalDataSource INSTANCE;

    public static PreferencesLocalDataSource getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new PreferencesLocalDataSource();
        }
        return INSTANCE;
    }

    private PreferencesLocalDataSource() {
        String name = AppLpds.getInstance().getPackageName();
//        Ll.i("PreferencesLocalDataSource", "获取SharedPreferences: " + name);
        mSharedPreferences =AppLpds.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
    }

    @Override
    public boolean contains(String key) {
        return mSharedPreferences.contains(key);
    }

    @Override
    public void clear() {
        mSharedPreferences.edit().clear().apply();
    }

    @Override
    public void setString(String key, String value) {
        mSharedPreferences.edit().putString(key, value).apply();
    }

    @Override
    public void setBoolean(String key, boolean value) {
        mSharedPreferences.edit().putBoolean(key, value).apply();
    }

    @Override
    public void setInt(String key, int value) {
        mSharedPreferences.edit().putInt(key, value).apply();
    }

    @Override
    public void setLong(String key, long value) {
        mSharedPreferences.edit().putLong(key, value).apply();
    }

    @Override
    public void setFloat(String key, float value) {
        mSharedPreferences.edit().putFloat(key, value).apply();
    }

    @Override
    public String getString(String key, String defaultValue) {
        return mSharedPreferences.getString(key, defaultValue);
    }

    @Override
    public boolean getBoolean(String key, boolean defaultValue) {
        return mSharedPreferences.getBoolean(key, defaultValue);
    }

    @Override
    public int getInt(String key, int defaultValue) {
        return mSharedPreferences.getInt(key, defaultValue);
    }

    @Override
    public long getLong(String key, long defaultValue) {
        return mSharedPreferences.getLong(key, defaultValue);
    }

    @Override
    public float getFloat(String key, float defaultValue) {
        return mSharedPreferences.getFloat(key, defaultValue);
    }
}

